package com.briup.bookstore.service.impl;

import com.briup.bookstore.dto.OrderCreateDTO;
import com.briup.bookstore.dto.OrderDeliveryDTO;
import com.briup.bookstore.dto.OrderPaySuccessDTO;
import com.briup.bookstore.dto.OrderSearchDTO;
import com.briup.bookstore.mapper.OrderMapper;
import com.briup.bookstore.po.ext.OrderExtend;
import com.briup.bookstore.service.OrderService;
import com.briup.bookstore.utils.BeanCopyUtils;
import com.briup.bookstore.vo.OrderDetailVO;
import com.briup.bookstore.vo.OrderInfoVO;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    OrderMapper orderMapper;

    @Override
    public PageInfo<OrderInfoVO> getPageOrder(Integer pageNum, Integer pageSize, OrderSearchDTO orderSearchDTO) {
        return null;
    }

    @Override
    public OrderDetailVO getOrderById(String orderId) {
        return null;
    }

    @Override
    public void closeOrder(String id) {

    }

    @Override
    public void delivery(OrderDeliveryDTO orderDeliveryDTO) {

    }

    @Override
    public void completeOrder(String orderId) {

    }

    @Override
    public List<OrderInfoVO> getOrders(int parseInt, OrderSearchDTO orderSearchDTO) {

        List<OrderExtend> orderExtends = orderMapper.selectListDetailByUserId(parseInt, orderSearchDTO);
        orderExtends.forEach(OrderExtend::genPrice);
        List<OrderInfoVO> orderInfoVOS = BeanCopyUtils.copyBeanList(orderExtends, OrderInfoVO.class);

        return orderInfoVOS;
    }

    @Override
    public OrderDetailVO createOrder(OrderCreateDTO orderCreateDTO, int parseInt) {
        return null;
    }

    @Override
    public void paySuccess(OrderPaySuccessDTO paySuccessDTO) {
        // 支付成功之后
        // 更新该订单的状态为已支付，并且新增新的支付时间和支付方式
        orderMapper.updateOrderStatusInPaySuccess(paySuccessDTO);
    }
}
